package com.springboot.controller.base;

import javax.servlet.http.HttpServletRequest;

import com.springboot.pojo.ResponsePojo;

public class BaseController {

	protected <T> ResponsePojo<T> getResponse(int code, long st, String desc, T body) {
		ResponsePojo<T> resPojo = new ResponsePojo<T>();
		resPojo.setCode(code);
		resPojo.setElapsedTime(System.currentTimeMillis() - st);
		resPojo.setBody(body);
		return resPojo;
	}

	protected String getIpAddr(HttpServletRequest request) {
		String ip = request.getHeader("x-forwarded-for");
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			ip = request.getHeader("Proxy-Client-IP");
		}
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			ip = request.getHeader("WL-Proxy-Client-IP");
		}
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			ip = request.getRemoteAddr();
		}
		return ip;
	}

}
